package org.softmed.rest.editor.comps.browser;

import java.awt.Color;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import net.miginfocom.swing.MigLayout;
import org.softmed.rest.editor.EditorUtil;
import org.softmed.rest.editor.commons.SwingUtil;

public class InfoBar extends JPanel {

	JLabel itemCount = new JLabel();
	JLabel totalItemCount = new JLabel();
	// JLabel itemsPerPage = new JLabel();

	JLabel totalPages = new JLabel();

	NavBar navBar = new NavBar();

	public InfoBar() {
		// setBackground(Color.WHITE);

		// SwingUtil.setSize(this, EditorUtil.restBrowserWidth, 20);
		MigLayout layout = new MigLayout("left,insets 0");
		setLayout(layout);

		add(navBar);

		add(new JLabel("i:"));
		add(itemCount, "w 20!");

		add(new JLabel("t:"));
		add(totalItemCount, "w 20!");

		// add(pages, "w 50!, h 20!");

		add(new JLabel("p:"));
		add(totalPages, "w 20!");

	}

	public void setPagedList(PagedList plist) {
		totalItemCount.setText("" + plist.getItemCount());

		if (plist.getItems() != null) {
			itemCount.setText(plist.getItems().size() + "");
		} else
			itemCount.setText("0");

		int totalPages = 0;
		if (plist.getItemsPerPage() != 0) {
			if (plist.getItemCount() <= plist.getItemsPerPage())
				totalPages = 1;
			else
				totalPages = (int) (plist.getItemCount() / plist
						.getItemsPerPage());
		}

		this.totalPages.setText("" + totalPages);
		// pages.removeAllItems();
		//
		// for (int i = 1; i <= totalPages; i++) {
		// pages.addItem(i);
		// }
		//
		// pages.setSelectedItem(plist.getCurrentPageNumber());
		navBar.setPagedList(plist);

	}

	public JComboBox getPages() {
		return navBar.getPages();
	}

	public NavBar getNavBar() {
		return navBar;
	}

	public void disableButtons() {
		navBar.disableButtons();
	}

	// public void enable() {
	// navBar.enableButtons();
	// }

}
